package avicit.bdp.dms.tdm.utils;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;

/** 常用方法 */
public class MethodUtils {

  /**
   * 去重(实体类中根据某个字段字段去重)
   *
   * @param keyExtractor keyExtractor
   * @param <T> T
   * @return <T> Predicate<T>
   */
  public static <T> Predicate<T> distinct(Function<? super T, Object> keyExtractor) {
    Map<Object, Boolean> seen = new ConcurrentHashMap<>();
    return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
  }

  /**
   * 试飞共享审核字段转化（与流程状态转化）
   *
   * @param stateCode
   * @return
   */
  public static String processStateToCheckStatus(String stateCode) {
    String state = "";
    if (Objects.equals("active", stateCode)) {
      state = "2";
    } else if (Objects.equals("ended", stateCode)) {
      state = "3";
    } else if (Objects.equals("start", stateCode)) {
      state = "1";
    }
    return state;
  }

  /**
   * 试飞共享审核字段转化（与流程状态转化）
   *
   * @param stateCode
   * @return
   */
  public static String processStateToCheckStatusName(String stateCode) {
    String stateName = "";
    if (Objects.equals("active", stateCode)) {
      stateName = "待审核";
    } else if (Objects.equals("ended", stateCode)) {
      stateName = "已完成审核";
    } else if (Objects.equals("start", stateCode)) {
      stateName = "编制中";
    }
    return stateName;
  }
}
